package com.wobangkj.common.api.crud;

import com.wobangkj.common.model.crud.Job;
import com.wobangkj.common.service.JobService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/job")
public class JobController {
    @Autowired
    private JobService JobService;

    @PostMapping(value = "/create")
    public Object create(@RequestBody Job data) {
        // 创建时间
        data.setCreatetime(Timestamp.valueOf(LocalDateTime.now()));
        return JobService.create(data);
    }

    @PutMapping(value = "/update")
    public Object update(@RequestBody Job job) {

        return JobService.update(job);
    }

    @DeleteMapping(value = "/delete/{id}")
    public Object delete(@PathVariable(value = "id") Long id) {
        return JobService.delete(id);
    }

    @GetMapping("/id")
    public Object id(Long id) {

        return JobService.id(id);
    }


    @GetMapping("/search")
    public Object search(@RequestParam(required = false) Map<String, Object> params, Job job) {
        return JobService.search(params, job);
    }

    //模糊查询

    @GetMapping("/findByNameLike/{job_name}")
    public List<Job> findByNameLike(@PathVariable(value = "job_name") String job_name){
        // 一定要加 "%"+参数名+"%"
        return JobService.findByNameLike(job_name);
    }

    @GetMapping("/selectAllJobView")
    public List<Object> selectAllJobView(){
        return JobService.selectAllJobView();
    }

    @GetMapping("/list")
    public List<Map> list(){
        return JobService.list();
    }

    @GetMapping("/listByNum")
    public List<Map> listByNum(){
        return JobService.listByNum();
    }

    @GetMapping("/listScreen")
    public List<Map> list(@RequestParam("company_name")String company_name,@RequestParam("company_num")Integer company_num,@RequestParam("company_finance")Integer company_finance, @RequestParam("college")Integer college,@RequestParam("major")Integer major, @RequestParam("job_class")Integer job_class,@RequestParam("job_class_second")Integer job_class_second){
        return JobService.list(company_name,company_num,company_finance,college,major,job_class,job_class_second);
    }

    @GetMapping("/idlist")
    public List<Map> idlist(long id){
        return JobService.idlist(id);
    }

    @GetMapping("/getListByName")
    public List<Map> getListByName(String name){
        return JobService.getListByName(name);
    }

    @PostMapping(value = "/updateForward")
    public Object updateJobForward(Long id) {
        return JobService.updateJobForward(id);
    }

    @GetMapping("/headimgList")
    public List<Map> headimgList(long id){
        return JobService.headimgList(id);
    }
}
